$(function(){
    let operas;
    $.ajax({
        url: 'https://www.fastmock.site/mock/bb4157f45a0b5ffdcb3f6d984517a6c0/woniuMovie/getAllOperas',
        success (data) {
            operas = data.operas;
            render();
        }
    });
    // 渲染页面
    function render() {
        operas.forEach(opera => {
            $(".brand ul").append($(
                `<li>${opera.name}</li>`
            ));
            $("#cinemalist").append($(
                `<li>
                    <div>
                        <p>${opera.name}</p>
                        <span>${opera.address}</span>
                        <i>改签</i><i>折扣卡</i>
                    </div>
                    <div>
                        <p>￥23<em>起</em></p>
                        <span>24km</span>
                    </div>
                    <div>选座购票</div>
                </li>`
            ));
        });
    }

    $("#cinemalist").on('click','div:last-child',function(e){
        if (location.search == "") {
            location.assign("film.html");
        }else{
            let opera = operas.find(opera => opera.name == $(this).prev().prev().children().first().text());
            location.assign(`cinema_details.html${location.search}id=${opera.id}`);
        }
    })
});
